﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VOL;
using BLL;
using System.Data;
using System.Data.SqlClient;


namespace WebShoes.Admin
{
    public partial class ThanhPhoForm : System.Web.UI.Page
    {
        ThanhPhoBL _ThanhPhoBL = new ThanhPhoBL();
        int maThanhPho = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string _maThanhPho = Request.QueryString["MaThanhPho"];
                if (_maThanhPho == null || _maThanhPho == "" || !int.TryParse(_maThanhPho, out maThanhPho))
                {
                    hdfMaThanhPho.Value = "0";
                }
                else
                {
                    DataTable dt = _ThanhPhoBL.searchIDThanhPho(maThanhPho);

                    txtTenThanhPho.Text = dt.Rows[0]["TenThanhPho"].ToString();

                    hdfMaThanhPho.Value = _maThanhPho;
                }
            }

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string _MaThanhPho = hdfMaThanhPho.Value;
            if (_MaThanhPho == null || _MaThanhPho == "0")
            {
                // thực hiện thêm mới
                ThanhPho obj = new ThanhPho();
                obj.TenThanhPho = txtTenThanhPho.Text;
                _ThanhPhoBL.insertThanhPho(obj);
            }
            else
            {
                // thực hiện sửa
                ThanhPho obj = new ThanhPho();
                obj.TenThanhPho = txtTenThanhPho.Text;
                obj.MaThanhPho = int.Parse(_MaThanhPho);
                _ThanhPhoBL.updateThanhPho(obj);
            }

            Response.Redirect("~/Admin/ThanhPhoManagerForm.aspx");
        }
    }
}